package com.fsoft.core.common.base.entity;

import java.io.Serializable;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import org.apache.commons.lang3.StringUtils;

import com.alibaba.fastjson.annotation.JSONField;
import com.fsoft.core.Global;
import com.fsoft.core.common.serialize.Serializer;
import com.fsoft.core.common.serialize.imp.FastJsonSerializeImp;

/***
 * F-Soft 登录用户信息，实现SysUser信息复制
 * @package com.fsoft.core.common.base
 * @author Fish
 * @email it.fish2010@foxmail.com
 * @date 2019-12-11
 * @CopyRight © F-Soft
 */
public class UserVo implements Serializable {

	private String id;
	private String loginAcct;
	private String name;
	private String code;
	// 单位ID(供应商)
	private String orgId;
	private String orgName;
	// 科室ID
	private String deptId;
	private String deptName;
	// 地址
	private String location;
	// 地区ID
	@JSONField(serialize = false)
	private String areaId;
	@JSONField(serialize = false)
	private String areaName;
	// 角色ID
	private String roleId;
	private Integer isGongys;
	private String email;
	private String mobile;
	// 头像
	private String imgPath;

	/* 是否超级管理员：分配了admin角色 */
	private boolean isSuperAdmin;

	private boolean isSystemAdmin;

	private boolean isSupplier;

	private boolean isNormalUser;
	/** theme 每个用户有自己的皮肤信息 */
	private String currTheme;
	// 帐号的权限标识
	@JSONField(serialize = false)
	private Set<String> permsSet = new HashSet<String>();
	// 帐号的角色列表
	@JSONField(serialize = false)
	private Set<String> roleSet = new HashSet<String>();

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public String getLoginAcct() {
		return loginAcct;
	}

	public void setLoginAcct(String loginAcct) {
		this.loginAcct = loginAcct;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getCode() {
		return code;
	}

	public void setCode(String code) {
		this.code = code;
	}

	public String getDeptId() {
		return deptId;
	}

	public void setDeptId(String deptId) {
		this.deptId = deptId;
	}

	public String getDeptName() {
		return deptName;
	}

	public String getLocation() {
		return location;
	}

	public void setLocation(String location) {
		this.location = location;
	}

	public void setDeptName(String deptName) {
		this.deptName = deptName;
	}

	public String getRoleId() {
		return roleId;
	}

	public void setRoleId(String roleId) {
		this.roleId = roleId;
	}

	public Set<String> getPermsSet() {
		return permsSet;
	}

	public void addPermsSet(List<String> perms) {
		this.permsSet.addAll(perms);
	}

	public Set<String> getRoleSet() {
		return roleSet;
	}

	public void addRoleSet(List<String> roleSet) {
		this.roleSet.addAll(roleSet);
	}

	public String getCurrTheme() {
		return currTheme;
	}

	public void setCurrTheme(String currTheme) {
		this.currTheme = currTheme;
	}

	public String getOrgId() {
		return orgId;
	}

	public void setOrgId(String orgId) {
		this.orgId = orgId;
	}

	public String getOrgName() {
		return orgName;
	}

	public void setOrgName(String orgName) {
		this.orgName = orgName;
	}

	public String getAreaId() {
		return areaId;
	}

	public void setAreaId(String areaId) {
		this.areaId = areaId;
	}

	public String getAreaName() {
		return areaName;
	}

	public void setAreaName(String areaName) {
		this.areaName = areaName;
	}

	public String getEmail() {
		return email;
	}

	public void setEmail(String email) {
		this.email = email;
	}

	public String getMobile() {
		return mobile;
	}

	public void setMobile(String mobile) {
		this.mobile = mobile;
	}

	public String getImgPath() {
		return imgPath;
	}

	public void setImgPath(String imgPath) {
		this.imgPath = imgPath;
	}

	public Integer getIsGongys() {
		if (!StringUtils.equals(Global.DEFAULT_ORG_ID, getOrgId()))
			this.isGongys = 1;
		else
			this.isGongys = 0;
		return isGongys;
	}

	/***
	 * 超级管理员角色
	 * @author fsoft
	 * @date 2021-09-24
	 * @return
	 */
	public boolean isSuperAdmin() {
		this.isSuperAdmin = hasRoleId(Global.SYS_ROLE_ID_ADMIN);
		return this.isSuperAdmin;
	}

	/**
	 * 系统管理员角色
	 * @author fsoft
	 * @date 2021-09-24
	 * @return
	 */
	public boolean isSystemAdmin() {
		this.isSystemAdmin = hasRoleId(Global.SYS_ROLE_ID_SYSTEM);
		return this.isSystemAdmin;
	}

	/***
	 * 普通帐号角色
	 * @author fsoft
	 * @date 2021-09-24
	 * @return
	 */
	public boolean isNormalUser() {
		this.isNormalUser = hasRoleId(Global.SYS_ROLE_ID_NORMAL);
		return this.isNormalUser;
	}

	/***
	 * 包含供应商角色
	 * @author fsoft
	 * @date 2021-09-24
	 * @return
	 */
	public boolean isSupplier() {
		this.isSupplier = hasRoleId(Global.SYS_ROLE_ID_SUPPLIER);
		return isSupplier;
	}

	public boolean hasRoleId(String roleId) {
		return roleSet.contains(roleId);
	}

	@Override
	public String toString() {
		return toString(serializer);
	}

	public String toString(Serializer serializer) {
		return serializer.Serialize(this);
	}

	private static final Serializer serializer = new FastJsonSerializeImp();
}
